******************************* Generates Simple Scores as a sum of the constituent proxy measures for cognitive ability, extraversion, emotional stability, and conscientiousness

clear
set more off
pause on

cd ""

use factor_data_base

global stable "_1*"
global cognit "_2*"
global extrav "_3*"
global consci "_4*"
 

* need to make the numeracy component of cognitive skill 0-1 also, in line with the rest
replace _2cognit_3c_1=_2cognit_3c_1+4.05817
 
********************* Normalizing so that all vars are on a 0-1 scale

foreach var of varlist $stable $cognit $extrav $consci {
	sum `var'

	gen temp=`var'/`r(max)'
		
	drop `var'
	rename temp `var'
	}


* j serves for correct ordering of factor scores in matlab export	
local j=1
foreach fac in stable cognit extrav consci {
	capture drop sc_all_`j'`fac'_all
	gen sc_all_`j'`fac'=0
	foreach var of varlist $`fac' {
		replace sc_all_`j'`fac'=sc_all_`j'`fac'+`var' 
		}
	local ++j	
	}

gen ind_id=_n
sort ind_id

save factor_scores, replace